from flask import Blueprint, request, url_for, session, redirect

admin_blue = Blueprint("admin", __name__, url_prefix="/admin")

from . import views


@admin_blue.before_request
def check_admin():
    is_admin = session.get("is_admin", False)
    # 如果不是管理员,直接跳转到主页
    if not is_admin and not request.url.endswith(url_for("admin.login")):
        return redirect('/')
